app.controller('settingsController', ['$rootScope', '$scope', '$parse', '$http', 'toolsServices', 'userServices', function($rootScope, $scope, $parse, $http, toolsServices, userServices)
{
	$rootScope.currentUser = userServices.getLoggedUser();
		
	/**
	* Get the configuration
	*/
	$scope.getConfigurationCommand = function() {
		try {
			$scope.loadingConfiguration = true;
			toolsServices.getConfiguration (function (data) {
				console.debug('toolsServices get configuration received');
				if(data.isFailed) {
					toastr.warning(data.exception, "Gestionnaire de configuration");
				}
				else {
					$scope.parameters = data.response;
				}
				$scope.loadingConfiguration = false;
			});
		}
		catch(exception) {
			toastr.error(exception, "Gestionnaire de configuration");
		}
	};
	
	/**
	* Get all versions details
	*/
	$scope.getVersions = function() {
		var versionsLoader = $.getJSON("./../versions.json", function() {
		})
		.done(function(json) {
			console.log('Versions loaded', "System");
			$scope.versions = json;
		})
		.fail(function(parametersLoader, textStatus, error) {
			toastr.error("Impossible de charger les versions " + textStatus, "System");
		})
		.always(function() {
			console.log('Version file load process finished', "System");
		});
	};
	
	/**
	* get parameters files
	*/
	$scope.getParametersFilesCommand = function() 
	{
		try {
			$scope.loadingConfiguration = true;
			toolsServices.getConfigurationFiles (function (data) {
				console.debug('toolsServices get configuration received');
				if(data.isFailed) {
					toastr.warning(data.exception, "Gestionnaire de configuration");
				}
				else {
					$scope.filesParameters = data.response;
				}
				$scope.loadingConfiguration = false;
			});
		}
		catch(exception) {
			toastr.error(exception, "Gestionnaire de configuration");
		}
	};
	
	/**
	*	Load the settings component
	*/
	$scope.loadSettingsComponentCommand = function() 
	{
		console.info("loadSettingsComponentCommand - called");
		
		$scope.getConfigurationCommand();
		$scope.getVersions();
		$scope.getParametersFilesCommand();
	};
	
	$scope.loadSettingsComponentCommand();
}]);